package servlet;

import jakarta.servlet.annotation.WebServlet;
import service.UserService;
import service.UserServiceImpl;
import user.entity.User;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

//管理员专用增加
@WebServlet(name="addUserServlet",urlPatterns = "/addUserServlet")
public class addUserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");
        String num=request.getParameter("uNum");
        String name=request.getParameter("uName");
        String sex=request.getParameter("uSex");
        String grade=request.getParameter("uGrade");
        String major=request.getParameter("uMajor");
        String number=request.getParameter("uNumber");
        String direction=request.getParameter("uDirection");
        String skill=request.getParameter("uSkill");
        String self=request.getParameter("uSelf");
        String password=request.getParameter("uPwd");
        User user=new User(num,name,sex,grade,major,number,direction,skill,self,password);
        UserService userService=new UserServiceImpl();
        boolean result=userService.addUser(user);
        if(result)
           request.setAttribute("error","noAddError");
        else
            request.setAttribute("error","addError");
        request.getRequestDispatcher("queryAllServlet").forward(request,response);
    }



    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
}
